<template>
  <div class="table-container">
    <section class="query-container">
      <el-row :gutter="20">
        <el-col>
          <layout :title="$t('local.name')">
            <el-input
              v-model="state.query.name"
              placeholder="请输入名称"
              style="width: 200px"
            ></el-input>
          </layout>
          <layout :title="$t('local.address')">
            <el-input
              v-model="state.query.address"
              placeholder="请输入地址"
              style="width: 200px"
            ></el-input>
          </layout>
          <layout :title="$t('local.province')">
            <el-select v-model="state.query.city" placeholder="请选择">
              <el-option
                v-for="item in state.options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </layout>
          <el-button type="primary">{{ $t('local.btns.search') }}</el-button>
          <el-button>{{ $t('local.btns.reset') }}</el-button>
          <el-button v-has="'create'">创建</el-button>
        </el-col>
      </el-row>
    </section>
    <el-table :data="state.list" v-loading="state.listLoading" border style="width: 100%">
      <el-table-column fixed prop="date" :label="$t('local.date')" width="150" />
      <el-table-column prop="name" :label="$t('local.name')" width="120" />
      <el-table-column prop="province" :label="$t('local.province')" width="120" />
      <el-table-column prop="city" :label="$t('local.city')" width="120" />
      <el-table-column prop="zip" :label="$t('local.postcode')" width="120" />
      <el-table-column prop="address" :label="$t('local.address')" />
      <el-table-column fixed="right" :label="$t('local.operation')" width="300">
        <template #default="scope">
          <el-button
            @click.prevent="handleRowEdit(scope.$index, state.list)"
            type="primary"
            size="small"
          >
            {{ $t('local.btns.inlineEdit') }}
          </el-button>
          <el-button
            @click.prevent="handleDialogEdit(scope.$index, state.list)"
            type="success"
            size="small"
          >
            {{ $t('local.btns.dialogEdit') }}
          </el-button>
          <el-button
            @click.prevent="handleDelete(scope.$index, state.list)"
            type="danger"
            size="small"
          >
            {{ $t('local.btns.delete') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="state.listQuery.currentPage"
      :page-sizes="[10, 30, 50, 100]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="state.total"
    />
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import layout from '@/components/SearchLayout/index.vue'

const state = reactive({
  list: [
    {
      date: '2016-05-02',
      name: '王小虎',
      province: '上海市',
      address: '上海市普陀区金沙江路 1518 弄',
      tag: '家',
      city: '普陀区',
      zip: 200333
    },
    {
      date: '2016-05-04',
      name: '王小虎',
      province: '上海市',
      address: '上海市普陀区金沙江路 1517 弄',
      tag: '公司',
      city: '普陀区',
      zip: 200333
    },
    {
      date: '2016-05-01',
      name: '王小虎',
      province: '上海市',
      address: '上海市普陀区金沙江路 1519 弄',
      tag: '家',
      city: '普陀区',
      zip: 200333
    },
    {
      date: '2016-05-03',
      name: '王小虎',
      province: '上海市',
      address: '上海市普陀区金沙江路 1516 弄',
      tag: '公司',
      city: '普陀区',
      zip: 200333
    },
    {
      date: '2016-05-04',
      name: '王小虎',
      province: '上海市',
      address: '上海市普陀区金沙江路 1517 弄',
      tag: '公司',
      city: '普陀区',
      zip: 200333
    },
    {
      date: '2016-05-01',
      name: '王小虎',
      province: '上海市',
      address: '上海市普陀区金沙江路 1519 弄',
      tag: '家',
      city: '普陀区',
      zip: 200333
    },
    {
      date: '2016-05-03',
      name: '王小虎',
      address: '上海市普陀区金沙江路 1516 弄',
      tag: '公司',
      province: '上海市',
      city: '普陀区',
      zip: 200333
    },
    {
      date: '2016-05-04',
      name: '王小虎',
      province: '上海市',
      address: '上海市普陀区金沙江路 1517 弄',
      tag: '公司',
      city: '普陀区',
      zip: 200333
    },
    {
      date: '2016-05-03',
      name: '王小虎',
      province: '上海市',
      address: '上海市普陀区金沙江路 1516 弄',
      tag: '公司',
      city: '普陀区',
      zip: 200333
    },
    {
      date: '2016-05-03',
      name: '王小虎',
      province: '上海市',
      address: '上海市普陀区金沙江路 1516 弄',
      tag: '公司',
      city: '普陀区',
      zip: 200333
    }
  ],
  listLoading: false,
  total: 400,
  listQuery: {
    currentPage: 1
  },
  options: [
    {
      value: '选项1',
      label: '黄金糕'
    },
    {
      value: '选项2',
      label: '双皮奶'
    },
    {
      value: '选项3',
      label: '蚵仔煎'
    },
    {
      value: '选项4',
      label: '龙须面'
    },
    {
      value: '选项5',
      label: '北京烤鸭'
    }
  ],
  query: {
    name: '',
    address: '',
    city: '',
    date: ''
  }
})
function handleSizeChange(val) {
  console.log(`每页 ${val} 条`)
}
function handleCurrentChange(val) {
  console.log(`当前页: ${val}`)
}
function handleDelete(index, row) {
  console.log(index, row)
}
function handleRowEdit(index, row) {
  console.log(index, row)
}
function handleDialogEdit(index, row) {
  console.log(index, row)
}
</script>

<style lang="scss" scoped>
.table-container {
  padding: 30px;
  .query-container {
    padding: 0 0 20px 0;
  }
}
</style>
